from django.db import models
from datetime import datetime


class CityDictModel(models.Model):
    """城市模型"""
    name = models.CharField(verbose_name='城市名', max_length=20, default='深圳市')
    desc = models.CharField(verbose_name='描述', max_length=200, default='这是一个文化中心')
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '城市'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class CourseOrg(models.Model):
    """课程机构模型"""
    catgory_type = (('pxjg', '培训机构'), ('gr', '个人'), ('gx', '高校'))

    name = models.CharField(verbose_name='机构名称', max_length=20)
    desc = models.TextField(verbose_name='机构描述', default='高大上')
    tag = models.CharField(verbose_name='机构标签', max_length=20, default='全国知名')
    catgory = models.CharField(verbose_name='机构类型', max_length=30, choices=catgory_type, default='pxjg')
    click_nums = models.IntegerField(verbose_name='点击数', default=0)
    fav_nums = models.IntegerField(verbose_name='收藏数', default=0)
    image = models.ImageField(upload_to='org/%Y/%m', verbose_name='封面图片')
    address = models.CharField(verbose_name='机构地址', max_length=100, blank=True, null=True, default='')
    city = models.ForeignKey(CityDictModel, on_delete=models.CASCADE, verbose_name='所在城市')
    students = models.IntegerField(verbose_name='学习人数', default=0)
    course_nums = models.IntegerField(verbose_name='课程数', default=0)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '课程机构'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

    def get_course_nums(self):
        # 获取课程数
        return self.coursemodel_set.all().count()


class TeacherModel(models.Model):
    """教师模型"""
    org = models.ForeignKey(CourseOrg, on_delete=models.CASCADE, verbose_name='所属机构')
    name = models.CharField(verbose_name='教师名', max_length=50)
    work_years = models.IntegerField(verbose_name='工作年限', default=1)
    work_company = models.CharField(verbose_name='就职公司', max_length=200, default='', blank=True, null=True)
    work_position = models.CharField(verbose_name='公司职位', max_length=20, default='教师', blank=True, null=True)
    points = models.CharField(verbose_name='教学特点', max_length=100, default='幽默...', blank=True, null=True)
    click_nums = models.IntegerField(verbose_name='点击数', default=0)
    fav_nums = models.IntegerField(verbose_name='收藏数', default=0)
    image = models.ImageField(verbose_name='头像', upload_to='teacher/%Y/%m', blank=True, null=True)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '教师'
        verbose_name_plural = verbose_name

    def __str__(self):
        return  self.name




















